home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol A-4 / (Vol A-4) Vol. A4.iso / Games / smashing.swf / scripts / frame_31 / DoAction.as
Text File  |  2008-03-12  |  11KB  |  295 lines

  1. function hitBrick(ball)
  2. {
  3.    ball.pixelsMoveX = (ball.testMoveX - ball.testMoveXTemp) / iterations;
  4.    ball.pixelsMoveY = (ball.testMoveY - ball.testMoveYTemp) / iterations;
  5.    b = 1;
  6.    while(iterations >= b)
  7.    {
  8.       ball.testMoveX = ball.testMoveXTemp + ball.pixelsMoveX * b;
  9.       ball.testMoveY = ball.testMoveYTemp + ball.pixelsMoveY * b;
  10.       if(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  11.       {
  12.          i = 1;
  13.          while(brickNumber >= i)
  14.          {
  15.             if(bricks["brick" + i].hitTest(ball.testMoveX,ball.testMoveY,true) && !bricks["brick" + i].brickSmashed)
  16.             {
  17.                activeBrick = bricks["brick" + i];
  18.                break;
  19.             }
  20.             i++;
  21.          }
  22.          break;
  23.       }
  24.       b++;
  25.    }
  26.    if(!activeBrick.invisible)
  27.    {
  28.       brickEdgeLeft = activeBrick._x - activeBrick._width / 2;
  29.       brickEdgeTop = activeBrick._y - activeBrick._height / 2;
  30.       brickEdgeBottom = activeBrick._y + activeBrick._height / 2;
  31.       brickEdgeRight = activeBrick._x + activeBrick._width / 2;
  32.       distanceToTopEdge = makePositive(ball.testMoveY - brickEdgeTop,true);
  33.       distanceToLeftEdge = makePositive(ball.testMoveX - brickEdgeLeft,true);
  34.       distanceToBottomEdge = makePositive(ball.testMoveY - brickEdgeBottom,true);
  35.       distanceToRightEdge = makePositive(ball.testMoveX - brickEdgeRight,true);
  36.       timeSinceLastBounce = getTimer() - ballLastBounced;
  37.       timeSinceLastBounce = 200;
  38.       if(!activeBrick.destructible && ball.powerBall or !ball.powerBall)
  39.       {
  40.          if(ball.SpeedX < 0 && ball.SpeedY < 0)
  41.          {
  42.             if(distanceToTopEdge < distanceToLeftEdge)
  43.             {
  44.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
  45.                {
  46.                   if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
  47.                   {
  48.                      hitEdge = "right";
  49.                      ballBounce(ball,activeBrick,hitEdge);
  50.                   }
  51.                   else
  52.                   {
  53.                      hitEdge = "left";
  54.                      ballBounce(ball,activeBrick,hitEdge);
  55.                   }
  56.                }
  57.                else
  58.                {
  59.                   hitEdge = "top";
  60.                   ballBounce(ball,activeBrick,hitEdge);
  61.                }
  62.             }
  63.             else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
  64.             {
  65.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
  66.                {
  67.                   hitEdge = "bottom";
  68.                   ballBounce(ball,activeBrick,hitEdge);
  69.                }
  70.                else
  71.                {
  72.                   hitEdge = "top";
  73.                   ballBounce(ball,activeBrick,hitEdge);
  74.                }
  75.             }
  76.             else
  77.             {
  78.                hitEdge = "left";
  79.                ballBounce(ball,activeBrick,hitEdge);
  80.             }
  81.          }
  82.          else if(ball.SpeedX < 0 && 0 < ball.SpeedY)
  83.          {
  84.             if(distanceToBottomEdge < distanceToLeftEdge)
  85.             {
  86.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
  87.                {
  88.                   if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
  89.                   {
  90.                      hitEdge = "right";
  91.                      ballBounce(ball,activeBrick,hitEdge);
  92.                   }
  93.                   else
  94.                   {
  95.                      hitEdge = "left";
  96.                      ballBounce(ball,activeBrick,hitEdge);
  97.                   }
  98.                }
  99.                else
  100.                {
  101.                   hitEdge = "bottom";
  102.                   ballBounce(ball,activeBrick,hitEdge);
  103.                }
  104.             }
  105.             else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
  106.             {
  107.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
  108.                {
  109.                   hitEdge = "bottom";
  110.                   ballBounce(ball,activeBrick,hitEdge);
  111.                }
  112.                else
  113.                {
  114.                   hitEdge = "top";
  115.                   ballBounce(ball,activeBrick,hitEdge);
  116.                }
  117.             }
  118.             else
  119.             {
  120.                hitEdge = "left";
  121.                ballBounce(ball,activeBrick,hitEdge);
  122.             }
  123.          }
  124.          else if(0 < ball.SpeedX && ball.SpeedY < 0)
  125.          {
  126.             if(distanceToTopEdge < distanceToRightEdge)
  127.             {
  128.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
  129.                {
  130.                   if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
  131.                   {
  132.                      hitEdge = "right";
  133.                      ballBounce(ball,activeBrick,hitEdge);
  134.                   }
  135.                   else
  136.                   {
  137.                      hitEdge = "left";
  138.                      ballBounce(ball,activeBrick,hitEdge);
  139.                   }
  140.                }
  141.                else
  142.                {
  143.                   hitEdge = "top";
  144.                   ballBounce(ball,activeBrick,hitEdge);
  145.                }
  146.             }
  147.             else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
  148.             {
  149.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
  150.                {
  151.                   hitEdge = "bottom";
  152.                   ballBounce(ball,activeBrick,hitEdge);
  153.                }
  154.                else
  155.                {
  156.                   hitEdge = "top";
  157.                   ballBounce(ball,activeBrick,hitEdge);
  158.                }
  159.             }
  160.             else
  161.             {
  162.                hitEdge = "right";
  163.                ballBounce(ball,activeBrick,hitEdge);
  164.             }
  165.          }
  166.          else if(0 < ball.SpeedX && 0 < ball.SpeedY)
  167.          {
  168.             if(distanceToBottomEdge < distanceToRightEdge)
  169.             {
  170.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true) && bricks.hitTest(ball.testMoveX,ball.testMoveY + 2,true) && !ball.LockedIn)
  171.                {
  172.                   if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true))
  173.                   {
  174.                      hitEdge = "right";
  175.                      ballBounce(ball,activeBrick,hitEdge);
  176.                   }
  177.                   else
  178.                   {
  179.                      hitEdge = "left";
  180.                      ballBounce(ball,activeBrick,hitEdge);
  181.                   }
  182.                }
  183.                else
  184.                {
  185.                   hitEdge = "bottom";
  186.                   ballBounce(ball,activeBrick,hitEdge);
  187.                }
  188.             }
  189.             else if(bricks.hitTest(ball.testMoveX - 2,ball.testMoveY,true) && bricks.hitTest(ball.testMoveX + 2,ball.testMoveY,true) && !ball.LockedIn)
  190.             {
  191.                if(bricks.hitTest(ball.testMoveX,ball.testMoveY - 2,true))
  192.                {
  193.                   hitEdge = "bottom";
  194.                   ballBounce(ball,activeBrick,hitEdge);
  195.                }
  196.                else
  197.                {
  198.                   hitEdge = "top";
  199.                   ballBounce(ball,activeBrick,hitEdge);
  200.                }
  201.             }
  202.             else
  203.             {
  204.                hitEdge = "right";
  205.                ballBounce(ball,activeBrick,hitEdge);
  206.             }
  207.          }
  208.       }
  209.    }
  210.    if((activeBrick.destructible or activeBrick.destructible == hitEdge) && !activeBrick.brickSmashed)
  211.    {
  212.       activeBrick.brickSmashed = true;
  213.       removeBrick(activeBrick,ball);
  214.       if(activeBrick.brickType != "bonus")
  215.       {
  216.          sndPop.start();
  217.       }
  218.    }
  219.    else if(activeBrick.multihit && !activeBrick.brickSmashed)
  220.    {
  221.       activeBrick.play();
  222.       sndIndestructibleHit.start();
  223.    }
  224.    else if(!activeBrick.invisible)
  225.    {
  226.       sndIndestructibleHit.start();
  227.    }
  228.    ball.randomizeMovementCounter = ball.randomizeMovementCounter + 1;
  229.    ball.randomSpeed = (Math.random() - 0.5) / 10;
  230.    ball.SpeedY += ball.randomSpeed;
  231.    ball.SpeedX += ball.randomSpeed;
  232. }
  233. function removeBrick(activeBrick, ball)
  234. {
  235.    if(!gameOver)
  236.    {
  237.       activeBrick.gotoAndPlay("remove");
  238.       activeBrick.ball = ball;
  239.       smashedBricks++;
  240.       bricksLeft = totalBricks - smashedBricks;
  241.       if(!activeBrick.expired)
  242.       {
  243.          addPoints(activeBrick,activeBrick.pointsWorth);
  244.       }
  245.       if(activeBrick.brickType != "bonus" && !ball.powerBall && !activeBrick.blownAway)
  246.       {
  247.          bonusActions();
  248.       }
  249.       if(bricksLeft < 1)
  250.       {
  251.          sndLevelCompleted.start();
  252.          clipCounter++;
  253.          attachMovie("mcPleaseWait","mcPleaseWait" + clipCounter,clipCounter);
  254.          this["mcPleaseWait" + clipCounter]._x = 320;
  255.          this["mcPleaseWait" + clipCounter]._y = 240;
  256.          bricks.play();
  257.       }
  258.       menu.txtBricksLeft = bricksLeft;
  259.    }
  260. }
  261. function brickMove(brickMovieClip, jumpsLeft, jumpsRight)
  262. {
  263.    if(!gamePaused)
  264.    {
  265.       if(getTimer() >= brickMovieClip.movingBrickPause)
  266.       {
  267.          if(0 < brickMovieClip.jumpsLeft && brickMovieClip.jumpsLeftCounter < brickMovieClip.jumpsLeft)
  268.          {
  269.             brickMovieClip._x -= 30;
  270.             brickMovieClip.jumpsLeftCounter = brickMovieClip.jumpsLeftCounter + 1;
  271.          }
  272.          else if(0 < brickMovieClip.jumpsRight && brickMovieClip.jumpsRightCounter < brickMovieClip.jumpsRight)
  273.          {
  274.             brickMovieClip._x += 30;
  275.             brickMovieClip.jumpsRightCounter = brickMovieClip.jumpsRightCounter + 1;
  276.          }
  277.          else
  278.          {
  279.             if(!brickMovieClip.moveBrickInit)
  280.             {
  281.                brickMovieClip.jumpsLeft += brickMovieClip.jumpsRightOrig - 1;
  282.                brickMovieClip.moveBrickInit = true;
  283.             }
  284.             brickMovieClip.jumpsLeftCounter = 0;
  285.             brickMovieClip.jumpsRightCounter = 0;
  286.             brickMovieClip._x -= 30;
  287.          }
  288.          brickMovieClip.movingBrickPause = movingBrickPauseOrig + getTimer();
  289.       }
  290.    }
  291. }
  292. multiHitPause = 2000;
  293. movingBrickPauseOrig = 1000;
  294. gotoAndPlay(40);
  295.